﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using QuanCafe.DataLayer;

namespace QuanCafe.BusinessLayer
{
    public class ItemType
    {
        public string activity;
        public int ItemTypeID;
        public string ItemTypeName;
        public string ItemTypeDesc;
        public int Rank;
        public string PostDate;
        public int Status;
        public string Creator;


        SQLHelper db = new SQLHelper();

        public DataTable GetAll()
        {
            try
            {
                db.AddParameter("@Activity", "GetAll", SqlDbType.NVarChar);
                return db.ExecuteReader("SP_ItemType", CommandType.StoredProcedure);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public DataRow GetByID()
        {
            try
            {
                db.AddParameter("@Activity", "GetByID", SqlDbType.NVarChar);
                db.AddParameter("@ItemTypeID", ItemTypeID, SqlDbType.Int);
                DataTable dtb = db.ExecuteReader("SP_ItemType", CommandType.StoredProcedure);

                if (dtb.Rows.Count > 0)
                    return dtb.Rows[0];
                else
                    return null;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public string InsertUpdate()
        {
            try
            {
                db.AddParameter("@Activity", activity, SqlDbType.NVarChar);
                db.AddParameter("@ItemTypeID", ItemTypeID, SqlDbType.Int);
                db.AddParameter("@ItemTypeName", ItemTypeName, SqlDbType.NVarChar);
                db.AddParameter("@ItemTypeDesc", ItemTypeDesc, SqlDbType.NVarChar);
                db.AddParameter("@Rank", Rank, SqlDbType.Int);
                db.AddParameter("@Creator", Creator, SqlDbType.NVarChar);
                db.AddParameter("@Status", Status, SqlDbType.Int);
                return db.ExecuteScalar("SP_ItemType", CommandType.StoredProcedure).ToString();
            }
            catch
            {
                return null;
            }
        }

        public bool CheckItemType()
        {
            try
            {
                db.AddParameter("@Activity", "CheckItemType", SqlDbType.NVarChar);
                db.AddParameter("@ItemTypeName", ItemTypeName, SqlDbType.NVarChar);
                string strResult = db.ExecuteScalar("SP_ItemType", CommandType.StoredProcedure);
                return strResult.ToLower() == "y" ? true : false;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        internal void ChangeActive()
        {
            try
            {
                db.AddParameter("@Activity", "ChangeActive", SqlDbType.NVarChar);
                db.AddParameter("@ItemTypeID", ItemTypeID, SqlDbType.Int);
                db.ExecuteScalar("SP_ItemType", CommandType.StoredProcedure);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
